package com.cosina.game.robodefence.findway;

import com.cosina.game.robodefence.util.World;

public class Path{
	public Path(int x, int y,Path before){
		this.x = x;
		this.y = y;
		if(null != before){
			setBefore(before);
			before.setNext(this);
		}
	}
	public Path before, next;
	
	public final int x,y;
	
	public String entryDirection = World.LEFT;
	public String exitDirection = World.RIGHT;
	
	
	public void setBefore(Path before){
		if(before.x == this.x  && before.y == this.y)
			throw new IllegalArgumentException("before is self");
		this.entryDirection = getDirection(this,before);
		this.before = before;
	}
	
	public void setNext(Path next){
		if(next.x == this.x  && next.y == this.y)
			throw new IllegalArgumentException("next is self");
		this.next = next;
		this.exitDirection = getDirection(next, this);
	}
	
	private static String getDirection(Path a, Path b){
		if(a.x == b.x){
			if(a.y > b.y){
				return World.BOTTOM;
			}else{
				return World.TOP;
			}
		}else{
			if(a.x > b.x){
				return World.RIGHT;
			}else{
				return World.LEFT;
			}
		}
	}
	
	public String toString(){
		return x + ":" + y;
	}
}